﻿using Ledict.ConditionExtract.Authority;
using Ledict.ConditionExtract.Base;
using Ledict.ConditionExtract.BLL;
using Ledict.Utility.Msg;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract.Frm
{
    /// <summary>
    /// 注册用户窗体
    /// </summary>
    public partial class RegeditForm : BaseForm
    {        
        public RegeditForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 取消按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void colBtnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 提交按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void colBtnRegedit_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(colTxtUserName.Text.Trim()))
                {
                    MsgBox.Warn("请输入用户名！");
                    colTxtUserName.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(colTxtUserDisplayName.Text.Trim()))
                {
                    MsgBox.Warn("请输入昵称！");
                    colTxtUserDisplayName.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(colTxtPassWord.Text))
                {
                    MsgBox.Warn("请输入密码！");
                    colTxtPassWord.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(colTxtPassWordAgain.Text))
                {
                    MsgBox.Warn("请再次输入密码！");
                    colTxtPassWordAgain.Focus();
                    return;
                }
                if (colTxtPassWord.Text != colTxtPassWordAgain.Text)
                {
                    MsgBox.Warn("两次密码输入不一致，请重新输入！");
                    colTxtPassWord.Focus();
                    return;
                }

                //Ledict.ConditionExtract.DAL.Authority.UserObject userObject = new DAL.Authority.UserObject();
                //userObject.m_userName= colTxtUserName.Text.Trim();
                //userObject.m_userDisplayName = colTxtUserDisplayName.Text.Trim();
                //userObject.m_passWord = colTxtPassWord.Text;
                //userObject.m_userDepartId = colComboxUserDepart.SelectedValue.ToString();
                //CoreUserBLL objCoreUserbll = new CoreUserBLL();
                //if (objCoreUserbll.AddUser(userObject))
                //{
                //    MsgBox.OK("恭喜您注册成功！");
                //    Close();                    
                //}
                //else
                //{
                //    MsgBox.Warn("注册失败！");
                //}
            }
            catch (Exception ex)
            {
                MsgBox.Err("发生错误：" + ex.Message);
            }
        }

        private void RegeditForm_Load(object sender, EventArgs e)
        {
            try
            {
                CoreDepartBLL coreDepartBll = new CoreDepartBLL();
                DataTable dtCoreDepart = coreDepartBll.GetCoreDepart();
                colComboxUserDepart.DataSource = dtCoreDepart;
                colComboxUserDepart.DisplayMember = "O_DepartName";
                colComboxUserDepart.ValueMember = "O_DepartId";            }
            catch (Exception ex)
            {
                MsgBox.Err("发生错误："+ex.Message);
            }
        }
    }
}
